import App from './App'
import uviewPlus from '@/uni_modules/uview-plus'
import mpShare from '@/uni_modules/uview-plus/libs/mixin/mpShare'
import GlobalLoginDialog from '@/components/GlobalLoginDialog/GlobalLoginDialog.vue'
import * as Pinia from 'pinia';

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import common from '@/config/common';
export function createApp() {
	const app = createSSRApp(App)
	app.config.globalProperties.$setBaseUrl = (url) => {
		if (!url) {
			return ''
		}
		//如果是数组
		if (Array.isArray(url)) {
			return url.map(item => {
				return app.config.globalProperties.$setBaseUrl(item)
			})
		}
		//如果是对象
		if (typeof url === 'object') {
			return Object.values(url).map(item => {
				return app.config.globalProperties.$setBaseUrl(item)
			})
		}
		//如果带有http 或 https 则直接返回
		if (url.indexOf('http') > -1) {
			return url
		}
		return common.API_BASE_URL + url;
	}
	app.component('GlobalLoginDialog', GlobalLoginDialog)
	app.use(uviewPlus)
	app.use(Pinia.createPinia());
	app.mixin(mpShare)
	return {
		app,
		Pinia
	}
}
// #endif